<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<div id="tips_sets"></div>
		<div id="loginpart">
			<div class="content-area items-display-flex flex-row flex-between">
				<div class="head-lab">
					<img src="../img/index/slogan.png" />
				</div>
				<div class="head-lab" v-if="loginState==0">
					<span id='login-btn' class="login" onclick="showLogin()">登录</span>
					<!--<span class="register" onclick="regUser()">微信注册</span>-->
					<!--<span class="user-center" onclick="toUsercenter()">个人中心</span>-->
					<span class="iconfont icon-dianhua"></span>全国加盟热线：400-900-4070
				</div>
				<div class="head-lab" v-else-if="loginState==1">
					<span class="login">{{nickname}}</span>
					<span class="register" v-on:click="loginout">退出</span>
					<span class="user-center" onclick="toUsercenter()">个人中心</span>
					<span class="iconfont icon-dianhua"></span>全国加盟热线：400-900-4070
				</div>
			</div>
			<div class="city-choose-panel"  v-if='loginshow==1'>
				<div class="panel">
					<div class="content poz-relative" style="padding: 50px;">
						<button class="close-btn" onclick="closeLogin()"><span class="iconfont icon-close"></span></button>
						<div class="logintitle"><span>手机号码快捷登录</span></div>
						<div class="horizon2"></div>
						<div class="phone">
							<input id="phonetxt" placeholder="输入手机号" v-model="mobile"
								 onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');"/>
						</div>
						<div class="horizon"></div>
						<div class="verifycode items-display-flex flex-row flex-between">
							<input placeholder="输入验证码" v-model="mobilecode" 
								onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');"/>
							<button v-on:click="sendCode()" id="codetxt" v-bind:class='[codeCanSend==1 ? "canSend":"cannotSend"]'>发送验证码</button>
						</div>
						
						<div class="horizon"></div>
						<div style="text-align:center; position: relative;top:25px;color: #FF0000;display: none;" id="errordiv">
							<span id="errortxt"></span>
						</div>
						<div class="login-btn">
							<button v-on:click="login()">立即登录</button>
						</div>
					</div>
				</div>
			</div>
			
			
			<div class="city-choose-panel"  v-if='baobeishow==1'>
				<div class="panel">
					<div class="content poz-relative" style="padding: 50px;">
						<button class="close-btn" @click="closeBaoBei"><span class="iconfont icon-close"></span></button>
						<div class="logintitle text-align-center">在线报备</div>
						<div class="baobei-tips">（预约看房至少提前一天）</div>
						<div class="items-display-flex flex-row baobei-options">
							<div><span @click='changeBaobeiStyle(1)' class="iconfont" v-bind:class='[baobeistyle==1 ? "icon-xuanzhong":"icon-weixuanzhong",baobeistyle==1 ? "baobei-options-active":""]'></span>自看</div>
							<div><span @click='changeBaobeiStyle(2)' class="iconfont" v-bind:class='[baobeistyle==2 ? "icon-xuanzhong":"icon-weixuanzhong",baobeistyle==2 ? "baobei-options-active":""]'></span>推荐</div>
						</div>
						<div class="bb-item">
							<div>联系人</div>
							<input v-model="reportman" style="padding-left: 10px;"/>
						</div>
						<div class="bb-item">
							<div>联系电话</div>
							<input style="padding-left: 10px;" v-model="reportphone" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');"/>
						</div>
						<div class="login-btn" style="margin-top: 40px;">
							<button @click='baobeiSubmit'>确认提交</button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script>
			
			var timeid = 0;
			var curtimes = 90;
			function toUsercenter(){
				window.location.href = 'user.html'
			}
			function showLogin(){
				loginpart.loginshow = 1;
			}
			
			function showLoginBind(buid){
				loginpart.loginshow = 1;
				if(buid){
					loginpart.loginUid = buid;
				}
				
			}
			
			function closeLogin(){
				loginpart.loginshow = 0;
				
				$("#errordiv").hide();
				$("#errortxt").html('');
				window.clearInterval(timeid);
				curtimes = 90;
			}
			
			function loginout(){
				Userloginout();
				loginpart.loginState = 0;
				loginpart.loginUid = 0;
				window.location.href = '../pages/index.html';
			}
			
			var loginpart = new Vue({
				el:'#loginpart',
				data:{
					loginshow:0,
					loginState:0,
					nickname:'',
					mobile:'',
					mobilecode:'',
					loginUid:'',
					codeCanSend:1,
					baobeishow:0,
					baobeistyle:1,
					reportman:'',
					reportphone:'',
					reportopt_status:'自看'
				},
				methods:{
					sendCode:function(){
						
						if(!this.mobile || this.mobile.length<6){
							$("#errordiv").show();
							$("#errortxt").html('请输入手机号码');
							return;
						}
							
						//发送验证码
						console.log('aabbcc');
						var urlstr = publicUrl + '/v1/wx-user/send-msg-pc';
						jQuery.post(urlstr, {
							mobile:this.mobile,
							uid:this.loginUid
						}, function(res) {
							
							if(res.code=="success"){
				                 //验证码发送返回
				                 //["mobile" => $mobile, "sms_code" => $rlt["sms_code"], "message" => "发送成功"]
				                 //loadUserInfo(loginBack,res.data.uid);
//				                 setTimeout(MsgCodeUpdate,1000)
								$("#errordiv").hide();
								$("#errortxt").html('');
								loginpart.codeCanSend = 0;
								timeid = setInterval("MsgCodeUpdate()",1000);
				            }
				            else {
								 //没有绑定手机
								 if(res.message == '-1'){
								 	$("#errordiv").show();
								 	$("#errortxt").html("手机未绑定,请先微信注册");
								 }
								 else{
								 	$("#errordiv").show();
								 	$("#errortxt").html(res.message);
								 }
								 
				            }
							
						});
					},
					login:function(){
						//登录
						var urlstr = publicUrl + '/v1/wx-user/pc-login';
						
						if(!this.mobile || this.mobile.length<6){
							$("#errordiv").show();
							$("#errortxt").html('请输入手机号码');
							return;
						}
						
						jQuery.post(urlstr, {
							mobile:this.mobile,
							sms_code: this.mobilecode,
							referee:0,
							uid:this.loginUid
						}, function(res) {
							if(res.code=="success"){
				                 //登录成功
				                 window.clearInterval(timeid);
				                 loadUserInfo(loginBack,res.data.uid);				                 
				            }
				            else {
								 //登录失败
								 if(res.message.code == '-1'){
								 	//调到授权页面
//								 	$("#errordiv").show();
//								 	$("#errortxt").html("手机未绑定,请先注册");
//								 	console.log(res);
								 	toWxUserInfoByPhone(res.message.phone);
								 }
								 else{
								 	$("#errordiv").show();
								 	$("#errortxt").html(res.message.msg);
								 }
				            }
							
						});
					},
					closeBaoBei:function(){
						this.baobeishow = 0;
					},
					changeBaobeiStyle:function(styleval){
						this.baobeistyle = styleval;
						if(styleval == 1){
							this.reportopt_status = '自己';
						}
						else if(styleval == 2){
							this.reportopt_status = '推荐';
						}
						
					},
					baobeiSubmit:function(){
						var userinfo = getUserInfo();
						if(!userinfo){
							showtips({},{tipsmsg:"请先登录!",tipstype:2});
							return;
						}
						
						if(!this.reportman){
							showtips({},{tipsmsg:"请填写联系人信息!",tipstype:2});
							return;
						}
						
						if(!this.reportphone || this.reportphone.length<11){
							showtips({},{tipsmsg:"请填写手机号码!",tipstype:2});
							return;
						}
						
						//在线报备。
						//data: {contacts:txt_contact,uid:user.uid,house_id:hid,phone:txt_mobile,referee:guider,status:opt_status},
						var urlstr = publicUrl+'/v1/report/add';
						jQuery.get(urlstr, 
							{
								contacts:this.reportman,
								uid:userinfo.uid,
								house_id:houseid,
								phone:this.reportphone,
								referee:1766,
								status:this.reportopt_status								
							},
							function(res) {
								if(res.code=="success"){
					                 showtips({},{tipsmsg:"报备成功!",tipstype:2});
					                 loginpart.baobeishow = 0;
					            }
					            else {
					            	showtips({},{tipsmsg:res.message,tipstype:2});
					            }
							
						});
						
					}
				}
			});
			
			function loginBack(){
				window.location.href = '../pages/user.html';
			}
			
			function MsgCodeUpdate(){
				curtimes-=1;
				if(curtimes > 0){
					$("#codetxt").text(curtimes+' s')
				}
				else{
					clearInterval(timeid);
					curtimes = 90;
					$("#codetxt").text('发送验证码');
					loginpart.codeCanSend = 1;
				}
			}
			
			function HeaderUserInfoUpdata(){
				var userinfo = getUserInfo();
				if(!userinfo){
					loginpart.loginState = 0;
				}
				else{
					loginpart.loginState = 1;
					loginpart.nickname = userinfo.nickname;
				}
			}
			
			//注册
			function regUser(){
				toWxUserInfo();
			}
			
			function showtips(objs,tipsobj){
				if(!maincnt.isloadtops){
					$('#tips_sets').load('../template/tips.html',function(){
						InitTip(tipsobj,objs);
						maincnt.isloadtops = true;
						showtipsPanel();
					});
				}
				else{
					showtipsPanel();
					InitTip(tipsobj,objs);
				}
		    }
			
			HeaderUserInfoUpdata();
			
			function tipsexitfun(objs){
				closePanl();
			}
		</script>
	</body>
</html>
